﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Collections;


namespace LED_Editor.Model
{
    public class FrameStructCollection :CollectionBase ,IList<FrameStruct>
    {

        public FrameStructCollection()
        {
            _innerHashTable = new Hashtable();
        }

        private void Racalculate()
        {
            int tempMarker = 0;

            for (int i = 0; i < Count; i++)
            {
                FrameStruct temp = this[i];

                temp.StartMarker = tempMarker;
                temp.EndMarker = this[i].StartMarker + (int)this[i].Duration;

                this[i] = temp;
                tempMarker = this[i].EndMarker;

            }
        }
        private Hashtable _innerHashTable;
        protected Hashtable InnerHashtable { get { return _innerHashTable; } }


        #region IList<FrameStruct> Members

        public void Add(FrameStruct str)
        {
            this.InnerList.Add(str);
            Racalculate();
        }

        public int IndexOf(FrameStruct item)
        {
           return  this.InnerList.IndexOf(item);
        }

        public void Insert(int index, FrameStruct item)
        {
            throw new NotImplementedException();
        }

        public void RemoveAt(int index)
        {
            throw new NotImplementedException();
        }

        public FrameStruct this[int index]
        {
            get
            {
                return (FrameStruct)this.InnerList[index];

            }
            set
            {
                this.InnerList[index]=value;
            }
        }

        #endregion

        #region ICollection<FrameStruct> Members


        public void Clear()
        {
            this.InnerList.Clear() ;
        }

        public bool Contains(FrameStruct item)
        {
            throw new NotImplementedException();
        }

        public void CopyTo(FrameStruct[] array, int arrayIndex)
        {
            throw new NotImplementedException();
        }

        public int Count
        {
            get { return this.InnerList.Count ; }
        }

        public bool IsReadOnly
        {
            get { throw new NotImplementedException(); }
        }

        public bool Remove(FrameStruct item)
        {
            throw new NotImplementedException();
        }

        #endregion

        #region IEnumerable<FrameStruct> Members

        public IEnumerator<FrameStruct> GetEnumerator()
        {
            return this.InnerList.OfType<FrameStruct>().GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return this.InnerList.GetEnumerator();
        }

        #endregion
    }
}
